home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 19 / 5 / DISK1959.ZIP / ACSORT.DOC next >
Text File  |  1989-07-23  |  19KB  |  385 lines

  1.  
  2.  
  3.                               INTRODUCTION
  4.     ACSORT, copyright (c) 1989, T.N.T. Software Inc., is a shareware 
  5. program; you may try it without any obligation to pay anything.  If you 
  6. do like it and use it after trying it, you should register your copy.  
  7. Registration will cost $25.  Registered users are entitled to support, 
  8. will be sent source code on request, and will be notified of updates.  
  9. If you are not a registered user, you should not expect support; please 
  10. do not call or write and ask for any.
  11.     You may post ACSORT and this documentation on bulletin boards, pass 
  12. it around to your friends, and make copies of it.  You may not sell 
  13. ACSORT without written permission from T.N.T. Software.
  14.     ACSORT (Advanced Cheapsort) was written by me, Bruce W. Tonkin.  
  15. About 90% of the program is Quick BASIC.  The remainder is assembler.  
  16. The assembler routines were printed in Dr. Dobbs' Magazine as a part of 
  17. several articles I wrote about general sorting techniques.
  18.  
  19.                          CAPABILITIES OF ACSORT
  20.     ACSORT is a disk-based sort/merge program.  It will sort data files 
  21. which have fixed-length records and fixed-length fields.  The data file 
  22. being sorted may be of any reasonable size, up to 268,402,689 records 
  23. long and up to 2,147,483,648 bytes (but sorting that many records would 
  24. probably take about six months on a fast machine).  You may have up to 
  25. 50 sort fields, provided that the total length of all sort keys does not 
  26. exceed 252 bytes.  If you need even longer keys, contact T.N.T. 
  27. Software; the modification for that is rather trivial, though it's not 
  28. likely to be needed.
  29.     The output file will be a list of record numbers (an index to the 
  30. data file in sorted order).  The index itself can be read as either a 
  31. sequential file or a random file with a record length of 12.  To save 
  32. disk space and increase sort speed, ACSORT will not output a whole 
  33. sorted file; if you need such output, see the sample programs at the end 
  34. of this documentation.  The sample programs also show how to use the 
  35. index to read the data file in sorted order.
  36.     ACSORT will not sort sequential data files, such as those written 
  37. using a word processor; it is only intended for use with true random 
  38. files.  For that reason, it will NOT sort dBase data files.  dBase files 
  39. are not random files: the first part of the file is a variable-length 
  40. header and is not part of the data nor is it the same length as any of 
  41. the data records.  ACSORT could be modified to read dBase files, at the 
  42. sacrifice of a fair amount of speed and efficiency (which is part of the 
  43. reason ACSORT is faster than dBase sorts, and Quick BASIC data base 
  44. programs are much faster than dBase applications).
  45.     ACSORT works correctly under PC DOS 2.0 and higher, and on hard 
  46. disks, floppy disks, and RAM (or memory) disks.  ACSORT is not copy 
  47. protected in any way, and may be backed up or transferred freely to 
  48. other media.  ACSORT is the copyrighted property of TNT Software Inc., 
  49. and may not be sold without written permission of TNT Software.
  50.     You may sort data of any type commonly used in any Microsoft 
  51. language.  Valid types include ASCII data (numbers or letters, in 
  52. alphabetic order), byte, packed integer or long integer, packed dates 
  53. (MDY format with each stored as a single character), dates in a variety 
  54. of other formats, packed single precision floating-point, packed double 
  55. precision, and any user-defined data type adhering to either the 
  56. Microsoft or IEEE floating point format.  Character or byte data may 
  57. contain control characters (of course, so may any of the other types).  
  58. Many other sorts have difficulty with other than ASCII data.
  59.     ACSORT is compatible with THE CREATOR, REPORTOR, PROGEN, REPGEN, and 
  60. other software sold or distributed by TNT SOFTWARE, INC.  For that 
  61. reason, any record composed entirely of ASCII character 250 in every 
  62. byte of every field will be skipped (counted as a deleted record).
  63.  
  64.                                     1
  65.  
  66.  
  67.     ACSORT is totally compatible with Microsoft BASIC random-access 
  68. files. Other sorts may have some difficulties with Microsoft random 
  69. files, even appending unwanted control characters or additional records 
  70. or pointers to the file output.  ACSORT will not.
  71.     You may sort unpacked numbers in numeric (rather than alphabetic) 
  72. order by choosing to sort that field as NUMERIC, rather than CHARACTER.  
  73. ACSORT will convert any such numbers into a packed double-precision 
  74. format internally; the sort will be accurate to 16 significant digits.
  75.     CSORT will:
  76.     (1) Read the command line for the name of the parameter file.
  77.     (2) Support subdirectories and path names for all file names.
  78.     (3) Buffer records internally for added speed.
  79.     (4) Allow records to be selected for or excluded from the sort.
  80.  
  81.     ACSORT will only output an INDEX to the file in sorted order.  This 
  82. index will consist of a list of record numbers.  By reading the sorted 
  83. file in the order specified by the index, you will be reading the file 
  84. in the sorted order you specified.
  85.     For your added convenience, the sort index file can be read as a 
  86. random file of record length 12.  This will allow you to use the index 
  87. file to do binary searches of the data, if you wish.  To help you 
  88. further, ACSORT will always tell you exactly how many records were 
  89. sorted when the sort has been completed.
  90.  
  91.                         SETTING UP THE PARAMETER FILE
  92.  
  93.     ACSORT can read all the requested inputs from the parameter file.  
  94. You may also enter all the inputs (except select and exclude criteria) 
  95. manually, at the keyboard.  For illustration purposes, we'll call the 
  96. parameter file CSORT.DAT, which is assumed to be on the current drive 
  97. and in the current directory.  You may name the parameter file anything 
  98. you like and put it on any drive and in any directory you like.
  99.     All inputs should be on separate lines.  Multiple inputs on the same 
  100. line will usually cause errors of various types.
  101.     If an error is encountered while reading the CSORT.DAT file, ACSORT 
  102. will print a short descriptive error message: 'BAD INPUT FILE', 'BAD 
  103. OUTPUT FILE', etc.  Those error messages should enable you to find and 
  104. fix the error fairly easily.
  105.     When running the sort, the only things the user will generally see 
  106. on the screen are the sort copyright message, whatever messages are 
  107. appropriate ('sorting through record #', 'merging', and the sort 
  108. termination message.
  109.     The parameter file should contain the following items, on separate 
  110. lines (without line numbers) in the order specified.  You can create 
  111. this file with a word processor or text editor, if it will produce a 
  112. plain ASCII file, or use the same procedure as you would use to create a 
  113. BATCH FILE from DOS.
  114.     1. Name of the file to sort;
  115.     2. Record length for sort file;
  116.     3. Name of index file;
  117.     4. Starting position for key (if zero go to step 9);
  118.     5. Length of key;
  119.     6. Data type for key (C=character or packed half-precision, 
  120.        N=numeric, I=packed integer, O=old packed field type, F=IEEE-type 
  121.        floating-point, L=Long integer, D=3-byte packed date, X=Date as 
  122.        character string with year at end, Y=IEEE Floating-point single- 
  123.        precision number containing date, Z=IEEE Floating-point double- 
  124.        precision number containing date, y=Microsoft format single- 
  125.        precision number containing date, z=Microsoft format double- 
  126.        precision number containing date.);
  127.  
  128.                                     2
  129.  
  130.  
  131.     7. Ascending or descending order (A/D);
  132.     8. Go back and repeat steps 4-7 until starting position is 0;
  133.     9. Work drive (A-Z is allowed, but you should NOT specify a 
  134.        subdirectory);
  135.    10. Selection or exclusion criteria.
  136.     All date fields may be in either MMDDYY or MMDDYYYY format except 
  137. packed date (D).  Packed date fields are assumed to have the month 
  138. stored as one byte, the day as one byte, and the year as one byte, in 
  139. that order.  Dates stored as character strings may use any delimiter or 
  140. no delimiter at all between day, month, and year--so long as the 
  141. delimiter is the same in each record.  However, the day field should 
  142. always be the same size for each record.  ACSORT will handle dates like 
  143. 12/13/46 and 4/15/87 by padding the second date with a 0 on the left.  
  144. It will not sort dates like 7/4/89 in correct order because the day is 
  145. only one byte long (and determining how to fix dates like 12-7-88 and 
  146. 4/14/77 would take too long to be worthwhile).
  147.     The beginning position of each key must be carefully specified.  The 
  148. easiest way to understand how this should be done is with an example.  
  149. Suppose you want to sort a data file whose record length is 85; the 
  150. fields in each record are of lengths 15, 20, 5, 20, 10, 10, and 5.  
  151. Suppose you want to sort each record by field 4, then 3, then 6, then 1.
  152.     In that case, the starting position of the first key (field 4) would 
  153. be 15+20+5+20=60, plus 1 (skip the first 60 characters, start the sort 
  154. at the 61st character).  The key length would be 20, if you want to sort 
  155. by all of the fourth field.  Likewise, the second key begins at 
  156. 15+20+1=36, the third key begins at 15+20+5+20+10+1=71, and the last key 
  157. begins at position 1.
  158.     You need not use all of a key field as a sort key.  If your key 
  159. field is very long (a name field, with 80 characters allowed, for 
  160. example), you may wish to use only the first few characters of the field 
  161. as the key.  Just enter whatever length you decide to use.
  162.     You may use any drive for your work files.  If you're sorting a 
  163. small-enough data file (under 16000 records) and you have a small enough 
  164. total key length (depends on memory available), you may not actually 
  165. need any work file.  There will always be two work files: $$$.TMP and 
  166. $$$$.TMP.  The second one is a dummy file used for internal buffering 
  167. and will not be used to actually write any data to disk.
  168.     In any event, the work file space necessary will not exceed your 
  169. total key lengths plus four bytes, rounded to the nearest higher power 
  170. of two (if not a power of two already), times the number of records in 
  171. the data file.  For example, if the total of key lengths is 50 bytes and 
  172. you are sorting 2000 records, the space required for your work file (if 
  173. needed) will be 64*2000=128000 bytes.  If the total length of all keys 
  174. is 28 bytes, the space required for work files (if any are needed) will 
  175. be 32*2000=64000 bytes.
  176.     When ACSORT begins to run, it will calculate how much memory is 
  177. available for the sort and display that number at the top of the screen. 
  178. Normally, on a 640K MSDOS machine there will be 300K to 400K bytes 
  179. available.  ACSORT uses much of the remaining memory for internal file 
  180. buffers and its own program code.  ACSORT will not hold more than 16,383 
  181. records internally, regardless of key length and memory available.  So, 
  182. it's possible that ACSORT might use as little as 128K for actual sort 
  183. space.
  184.     The output index will always take exactly 12 bytes per record 
  185. sorted.  The output index file will always be written before any work 
  186. files are deleted.
  187.     Be sure you have enough space available on the drives you designate 
  188. for your work and index files.  It is disheartening to run the sort 
  189. almost to completion and get a 'disk full' error message.
  190.  
  191.  
  192.                                     3
  193.  
  194.  
  195.     It is interesting to note, in this connection, that ACSORT uses 
  196. generally less work file space than other sorts.  You will probably find 
  197. that ACSORT will be capable of sorting data files other sorts cannot 
  198. touch.
  199.  
  200.                         RECORD SELECTION AND EXCLUSION
  201.  
  202.     You may select or exclude records by including command lines of the 
  203. form:
  204.  
  205. S,start,length,kind,relationship,value
  206. X,start,length,kind,relationship,value
  207.  
  208.     Lines beginning with the letter S are used to select records.  Lines 
  209. beginning with the letter X are used to exclude records from the sort.  
  210. You may enter selection and exclusion criteria in any order, but 
  211. exclusions will always be processed first.
  212.     The "start" parameter must be a number and should be the beginning 
  213. position of the part of the record used for selection or exclusion.  The 
  214. "length" parameter should be the number of characters to use.  The 
  215. "kind" parameter must be one of the letters I, O, N, C, F, L, or D.  The 
  216. letter I will be used to indicate a packed integer field; O will 
  217. indicate an old-style floating-point packed number (not IEEE format); N 
  218. indicates an unpacked numeric field; C is a character field; F is an 
  219. IEEE-format packed floating-point field; L is a packed long integer 
  220. field (4 bytes); and D is a packed date (3 characters, MDY format).
  221.     The relationship must be one of "<", ">", "<=", ">=", "<>", or "=".  
  222. The value should be the character string or numeric value against which 
  223. the field should be compared.
  224.     Here are some examples of selection and exclusion:
  225.  
  226. S,3,4,F,<,34.56
  227. Select only records for which the field starting at position 3 and going 
  228. for four bytes, when treated as an IEEE floating-point number, is less 
  229. than 34.56.
  230.  
  231. X,57,10,C,>=,"FLOSTERMAN"
  232. Exclude records for which the field starting at position 57 and going 
  233. for ten bytes is greater than or equal to "FLOSTERMAN".
  234.  
  235.                            HOW TO RUN ACSORT
  236.  
  237.     Simple: while at the DOS prompt (A>, B>, etc.) just type in the name 
  238. of the ACSORT file you have decided to use, followed by the name of the 
  239. parameter file.  Use any drive or subdirectory specifiers necessary.
  240.     For example:
  241. ACSORT B:CSORT.PAR
  242. or
  243. C:\DOS\ACSORT B:\DATAFILE\CSORT.PAR
  244.  
  245.     Below are two sample parameter files you can use as templates for 
  246. your own sorting needs.  For each file, I have included an explanation 
  247. of the actual command lines appearing to the left.
  248.  
  249.                          SAMPLE PARAMETER FILES
  250. {Lines in the file}     {Explanation}
  251. CUSTLIST.DAT            Name of file to sort
  252. 138                     Record length
  253. CUSTLIST.INX            Name of output index file
  254. 8                       Starting position of first key
  255.  
  256.                                     4
  257.  
  258.  
  259. 25                      Length of key
  260. C                       Data type (capitalization counts!)
  261. A                       Ascending order
  262. 0                       Starting position of next key (0 for none)
  263.          <-------- note: if this line is left blank, the work drive will
  264.                    default to the current drive.  If this line does not 
  265.                    appear, ACSORT will ask the operator at run-time for 
  266.                    the letter of the work file drive.
  267.  
  268. CUSTLIST.DAT            Name of file to sort
  269. 138                     Record length
  270. CUSTLIST.INX            Name of index file
  271. 8                       Starting position of first key
  272. 25                      Length of first key
  273. C                       Data type of first key
  274. A                       Ascending order
  275. 4                       Starting position of second key
  276. 4                       Length of second key
  277. O                       Data type of second key
  278. D                       Descending order
  279. 0                       Starting position of third key (0 to stop)
  280. C                       Drive for work files is C
  281. X,4,4,O,<=,100          Exclude if field starting at 4 and going for 4 
  282.                         bytes, considered as old-style floating-point 
  283.                         number, is less than or equal to 100.
  284.  
  285.  
  286.  
  287.                             SORT PERFORMANCE
  288.  
  289.     The following speeds have been observed, running ACSORT on a 40 
  290. Megabyte Plus Development HardCard on a Tandy 4000 (80386, 16 MHz).  
  291. Times on a floppy disk will be longer and will depend on the drive type, 
  292. the media quality, and a number of other factors.  Times on better hard 
  293. disks will be less.
  294.  
  295.                    SORTING 24765 RECORDS OF 138 BYTES EACH
  296.  
  297.          Key Length  Type   Order        Time (sec)  Records/minute
  298.              12      Alpha  Ascending       225.0         6603
  299.              12      Alpha  Descending      224.4         6622
  300.              25      Alpha  Ascending       228.7         6497
  301.              25      Alpha  Descending      230.0         6460
  302.              25      Alpha  Ascending        52.1        28511*
  303.               4      Float  Ascending       226.1         6573
  304.               4      Float  Descending      222.2         6687
  305.  
  306. *565 records were extracted via "exclude" from 24,765 and actually 
  307. indexed.
  308.  
  309.                     SORTING 2087 RECORDS OF 131 BYTES EACH
  310.  
  311.          Key Length  Type   Order        Time (sec)  Records/minute
  312.              25      Alpha  Ascending        11.1        11287
  313.              25      Alpha  Descending       11.2        11181
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.                                     5
  321.  
  322.  
  323.         SAMPLE GWBASIC PROGRAM TO READ A DATA FILE VIA AN INDEX
  324.                      AND CREATE A WHOLE FILE OUTPUT
  325.  
  326. 10 LINE INPUT"File to read:";F$
  327. 20 LINE INPUT"File to write:";W$
  328. 30 LINE INPUT"Index file name:";I$
  329. 40 INPUT"Record length:";R:'If record length >255 you will need to alter
  330. 50 OPEN"R",1,F$,R:'   lines 60 and 80 for a more complicated
  331. 60 FIELD #1,R AS A$:'  field statement. use as many variables as needed
  332. 70 OPEN"R",2,W$,R:'   to use up all the characters in each record.
  333. 80 FIELD #2,R AS B$:'  For example:
  334. 90 OPEN"I",3,I$:'    FIELD #1, 255 AS A1$,255 AS A2$,255 AS A3$
  335. 91 '           Will handle a record of 765 bytes. you will
  336. 92 '           need to field #2 similarly, and do the LSETs in line
  337. 93 '           110 as well. The LSETs can be done like this:
  338. 94 '           LSET B1$=A1$:LSET B2$=A2$:LSET B3$=A3$
  339. 95 '           Further note: if your record length exceeds 128, you
  340. 96 '           should be sure to enter basic with the /s: switch
  341. 97 '           set appropriately.  See your basic manual.
  342. 100 PRINT"Transferring":ON ERROR GOTO 500
  343. 110 INPUT #3,A:GET 1,A:LSET B$=A$:COUNT=COUNT+1:PUT 2,COUNT
  344. 120 GOTO 110
  345. 500 PRINT"Done.";COUNT;"Records transferred."
  346. 510 CLOSE:END
  347.  
  348.        SAMPLE QUICKBASIC PROGRAM TO READ A DATA FILE VIA AN INDEX
  349.                      AND CREATE A WHOLE FILE OUTPUT
  350.  
  351.  DEFLNG A-Z
  352.  LINE INPUT"File to read:";f$
  353.  LINE INPUT"File to write:";w$
  354.  LINE INPUT"Index file name:";i$
  355.  INPUT"Record length:";r
  356.  OPEN"R",1,f$,r: FIELD #1,r as a$
  357.  OPEN"R",2,w$,r: FIELD #2,r as b$
  358.  OPEN"I",3,i$
  359.  PRINT"Transferring"
  360.  while not eof(3)
  361.     INPUT #3,a:GET 1,a:LSET b$=a$:count=count+1:PUT 2,count
  362.  wend
  363.  PRINT"Done.";count;"Records transferred."
  364.  CLOSE:END
  365.  
  366.                      THANKS FOR PURCHASING ACSORT!
  367. For a catalog of our other inexpensive, high-quality software for the 
  368. IBM PC or compatibles, write to:
  369.  
  370.                          T.N.T. SOFTWARE, INC.
  371.                          34069 HAINESVILLE ROAD
  372.                           ROUND LAKE, IL 60073
  373.                              (312) 223-0832
  374.  
  375. IBM PC is a registered trademark of The IBM Corporation; THE CREATOR, 
  376. REPORTOR, PROGEN, REPGEN, and ACSORT are trademarks of T.N.T. SOFTWARE, 
  377. INC.
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.                                     6
  385.